String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g, ""); } 
$.validator.setDefaults({
	submitHandler: function(form) {form.submit(); },
	errorPlacement: function(error, element) {
		var flag = false;
		var spanEl = $(element).parent().find("span");
		if (spanEl != null && spanEl.length > 0) {
			for ( var i = 0; i < spanEl.length; i++) {
				if($(spanEl[i]).attr("class") == "validError") {
					$(spanEl[i]).append(error);
					flag = true;
				}
			}
		}
		if (!flag) {
			error.appendTo($(element).parent());
		}
	}

});

jQuery.validator.addMethod("noEqual", function(value, element,param) {  
	return this.optional(element) || (value != param);   
}, "两个值相同");  


//验证值小数位数不能超过两位
jQuery.validator.addMethod("decimal", function(value, element) {
	 var decimal = /^-?\d+(\.\d{1,2})?$/;
	 return this.optional(element) || (decimal.test(value));
}, $.validator.format("小数位数不能超过两位!"));

jQuery.validator.addMethod("registerTel",function(value,element) {    
	  var length = value.length;  
	  return this.optional(element) || (length == 11 && /^(((13[0-9]{1})|(15[0-9]{1}))+\d{8})$/.test(value));    
	},"请正确填写您的手机号码"); 

//电话号码验证       
jQuery.validator.addMethod("isTel", function(value, element) {       
  var tel = /^\d{3,4}-?\d{7,9}$/;    //电话号码格式010-12345678   
  return this.optional(element) || (tel.test(value));       
}, "请正确填写您的电话号码");   

//联系电话(手机/电话皆可)验证   
jQuery.validator.addMethod("isPhone", function(value,element) {   
    var length = value.length;   
   var mobile = /^(((13[0-9]{1})|(15[0-9]{1}))+\d{8})$/;   
   var tel = /^\d{3,4}-?\d{7,9}$/;   
   return this.optional(element) || (tel.test(value) || mobile.test(value));   
  
}, "请正确填写您的联系电话");   


//手机验证   
jQuery.validator.addMethod("isMobile", function(value,element) {   
    var length = value.length;   
   var mobile = /^(((13[0-9]{1})|(15[0-9]{1}))+\d{8})$/;   
   return this.optional(element) || mobile.test(value);   
}, "请正确填写您的联系电话");   


